<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        .nav{
            height: 50px;
            background-color: coral;
        }
        .center{
            width: 1000px;
            height: 50px;
            margin: 0 auto;
            position: relative;
        }
        ul{
            position: absolute;
            list-style: none;
        }
        .center li{
            float: left;
        }
        .center li>a{
            text-decoration: none;
            color: #FFF;
            display: block;
            padding: 0 20px;
            line-height: 50px;
        }
        .center li:first-child>a{
            background: #F00;
        }
        .slide{
            width: 82px;
            height: 50px;
            background-color: #F00;
            position: absolute;
        }

    </style>
</head>
<body>

    <div class="nav">
        <div class="center">
            <div class="slide"></div>  
            <ul>
                <li><a href="#">菜单1</a></li>
                <li><a href="#">菜单2</a></li>
                <li><a href="#">菜单3</a></li>
                <li><a href="#">菜单4</a></li>
                <li><a href="#">菜单5</a></li>
                <li><a href="#">菜单6</a></li>
            </ul>
        </div>
    </div>

    <script src="21.js"></script>
    <script>
        var ul=document.querySelector("ul")
        var slide=document.querySelector(".slide")  //移动的滑块
        ul.addEventListener("mouseover",function(e){  //事件委托
            var e=e||window.event;
            if(e.target.tageName='A')
            {
                var left=e.target.offsetLeft;
                animate(slide,left,30)
            }
        })
        ul.addEventListener("mouseout",function(){  //事件委托

                animate(slide,0,30)
           
        })
    </script>
    
</body>
</html>